package com.rachel.wifimanagerdemo.adapter;
import android.content.Context;
import android.net.wifi.ScanResult;
import android.view.View;


import com.rachel.wifimanagerdemo.R;
import com.rachel.wifimanagerdemo.base.BaseRecycleAdapter;
import com.rachel.wifimanagerdemo.base.BaseViewHolder;

import java.util.List;

public class WifiListAdapter extends BaseRecycleAdapter<ScanResult> {

    private String currentSSID = "-1";

    public WifiListAdapter(Context context) {
        super(context, null);
    }

    @Override
    public void bindData(BaseViewHolder holder, ScanResult data, int position) {
        ScanResult scanResult = getItem(position);
        holder.setText(R.id.wifi_name_tv, scanResult.SSID);
        holder.setViewVisibility(R.id.wifi_pick_iv, currentSSID.equals("\"" + scanResult.SSID + "\"") ? View.VISIBLE : View.GONE);
        int level = scanResult.level;
        if (level <= 0 && level >= -50) {
            holder.setImageResource(R.id.wifi_signal_iv, R.mipmap.icon_wifi_3);
        } else if (level < -50 && level >= -80) {
            holder.setImageResource(R.id.wifi_signal_iv, R.mipmap.icon_wifi_2);
        } else {
            holder.setImageResource(R.id.wifi_signal_iv, R.mipmap.icon_wifi_1);
        }

    }

    public void updateConnectState(String SSID) {
        this.currentSSID = SSID;
        notifyDataSetChanged();
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.wifi_list_item;
    }

    @Override
    public void updateData(List<ScanResult> dataList) {
        super.updateData(dataList);
    }

    public boolean isCurrentConnectItem(String SSID) {
        return this.currentSSID.equals("\"" + SSID + "\"");
    }
}
